import handler.PrintStringHandler;
import my.netty.bootstrap.Bootstrap;
import my.netty.channel.Channel;
import my.netty.channel.ClientChannel;
import my.netty.channel.EventLoopGroup;
import my.netty.channel.handler.ChannelInitializer;
import my.netty.channel.nio.NioClientSocketChannel;
import my.netty.channel.nio.NioEventLoopGroup;

import java.io.IOException;
import java.nio.ByteBuffer;

public class SimpleClient {
    public static void main(String[] args) throws IOException {

        EventLoopGroup worker = new NioEventLoopGroup(1);
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(worker).channel(NioClientSocketChannel.class)
                .handler(new ChannelInitializer() {
                    @Override
                    public void initChannel(Channel channel) {
                        channel.pipeline().addFirst(new PrintStringHandler());
                    }
                });
        ClientChannel channel = bootstrap.connect("127.0.0.1", 8080);
        channel.writeAndFlush(ByteBuffer.wrap("客户端发送成功了".getBytes()));
    }
}
